package cn.edu.qut.edusys.util;
import org.springframework.mail.*;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.util.Date;
@Component
public class EmailUtil {

    @Resource
    private JavaMailSender javaMailSender;

    public int sendMail(String mail){
        int row=0;
        MimeMessage msg=javaMailSender.createMimeMessage();
       try {
           MimeMessageHelper helper=new MimeMessageHelper(msg,true);
          //发送的是个文本，文本是种html类型，
            helper.setText("<a href='http://localhost:8088/edusys/setNewPassword.html'>点我设置新密码！</a>",true);
            //发给我的邮箱
           helper.addTo("1980001551@qq.com");
           //从我的邮箱发送
           helper.setFrom("1980001551@qq.com");
            helper.setSubject("企业及软件设计教务系统找回密码");
            helper.setSentDate(new Date());
            javaMailSender.send(msg);
            row=1;
        } catch (MessagingException e) {
            e.printStackTrace();
        }
       return row;
   }
}
